package com.shiguiwu.springmybatis.spring.property;



import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

/**
 * @description: 自定义作用域
 * @author: stone
 * @date: Created by 2021/4/6 20:01
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.property
 */
public class BeanMyScope implements Scope {
   // @1：定义了一个常量，作为作用域的值
    public static final String scopeName = "shiguiwu";

    /**
     * @2：这个get方法是关键，自定义作用域会自动调用这个get方法来创建bean对象，这个地方输出了一行日志，为了一会方便看效果
     * @param name
     * @param objectFactory
     * @return
     */
    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        System.out.println("get method >>>>>>>>>>>>>>>>>>>>>" + name);
        //@3：通过objectFactory.getObject()获取bean实例返回
        return objectFactory.getObject();
    }

    @Override
    public Object remove(String name) {
        return null;
    }

    @Override
    public void registerDestructionCallback(String name, Runnable callback) {

    }

    @Override
    public Object resolveContextualObject(String key) {
        return null;
    }

    @Override
    public String getConversationId() {
        return null;
    }
}
